package org.easymodelers.gmf.utils;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.jar.Manifest;

public abstract class PluginUtils {

	public static Manifest loadManifest(String manifestPath) {
		Manifest manifest = new Manifest();
		InputStream inputStream = null;
		try {
			inputStream = new FileInputStream(manifestPath);
			manifest.read(inputStream);
			return manifest;
		} catch(Exception ex) {
			//TODO
		} finally {
			if (inputStream!=null) {
				try {
					inputStream.close();
				} catch (IOException e) {}
			}
		}
		return null;
	}

	public static void storeManifest(String manifestPath, Manifest manifest) {
		OutputStream outputStream = null;
		try {
			outputStream = new FileOutputStream(manifestPath);
			manifest.write(outputStream);
		} catch(Exception ex) {
			//TODO
		} finally {
			if (outputStream!=null) {
				try {
					outputStream.close();
				} catch (IOException e) {}
			}
		}
	}
	
	/*
Map map = manifest.getEntries(); // Enumerate each entry for (Iterator it=map.keySet().iterator(); it.hasNext(); ) { // Get entry name String entryName = (String)it.next(); // Get all attributes for the entry Attributes attrs = (Attributes)map.get(entryName); // Enumerate each attribute for (Iterator it2=attrs.keySet().iterator(); it2.hasNext(); ) { // Get attribute name Attributes.Name attrName = (Attributes.Name)it2.next(); // Get attribute value String attrValue = attrs.getValue(attrName); } } 	 */
}
